package com.xunker.appointment.exception;

import com.xunker.appointment.result.ResultCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("自定义异常")
public class AppointmentException extends RuntimeException {
    @ApiModelProperty("异常状态码")
    private Integer code;

    @Override
    public String toString() {
        return "AppointmentException{" +
                "code=" + code +
                '}';
    }

    /**
     * 通过状态码返回错误信息
     *
     * @param message
     * @param code
     */
    public AppointmentException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    public AppointmentException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }
}
